import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { CommonModule } from '@angular/common';

import { SigninComponent } from './signin/signin.component';
import { SignupComponent } from './signup/signup.component';
import { LayoutComponent } from './layout/layout.component';

import { ContactListComponent } from './contact-list/contact-list.component'
import { ContactEditComponent } from './contact-edit/contact-edit.component'
import { ContactNewComponent } from './contact-new/contact-new.component'

import { TagListComponent } from './tag-list/tag-list.component'
import { TagEditComponent } from './tag-edit/tag-edit.component'
import { TagNewComponent } from './tag-new/tag-new.component'


import {AuthGuard} from './auth.guard.services'

/**
 * 0，路由模块初始化：ng g module app-routing --flat --module=app
 * 1，配置路由表
 *    请求 xxx 路径的时候，导航到xxx组件
 * 2，配置路由出口，以及路由导航链接。
 */


const routes: Routes = [
  {
    path: '',
    redirectTo:'/contacts', // 重定向到contacts
    pathMatch: 'full', //完全匹配

  },
  {
    path: 'signin',
    component: SigninComponent,
  },
  
  {
    path: 'signup',
    component: SignupComponent,
  },
  {
    // 嵌套组件
    path: 'contacts',
    component: LayoutComponent,
    // 添加拦截
    canActivate:[AuthGuard],
    children:[
      {
        path: '',
        component:ContactListComponent,
      },
      {
        path: 'new',
        component: ContactNewComponent,
      },
      {
        path: 'edit/:id', //动态路径参数
        component: ContactEditComponent,
      }
    ]
  },

  {
    // 嵌套组件
    path: 'tags',
    component: LayoutComponent,
    children:[
      {
        path: '',
        component:TagListComponent,
      },
      {
        path: 'new',
        component: TagNewComponent,
      },
      {
        path: 'edit',
        component: TagEditComponent,
      }
    ]
  },
]


@NgModule({
  declarations: [],
  imports: [
    CommonModule,
    RouterModule.forRoot(routes),
  ],
  exports: [RouterModule],
  providers:[AuthGuard]
})
export class AppRoutingModule { }
